package javase.ch06.reflect;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class ReflectGenericDemo {
    public static void main(String[] args) {
        // 创建泛型为Integer的集合
        List<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(20);
        list.add(30);

        try {

            Class<?> listClass = list.getClass();

            Method addMethod = listClass.getMethod("add", Object.class);

            addMethod.invoke(list, "abc");

        } catch (Exception e) {
            e.printStackTrace();
        }

        // 输出结果：[10, 20, 30, abc]
        System.out.println(list);
    }
}